package cn.tedu.hhmc.user.service.impl;

import cn.tedu.hhmc.user.mapper.UserMapper;
import cn.tedu.hhmc.user.pojo.dto.UserLoginParam;
import cn.tedu.hhmc.user.pojo.entity.User;
import cn.tedu.hhmc.user.pojo.vo.UserVO;
import cn.tedu.hhmc.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.tedu.hhmc.base.exception.ServiceException;
import cn.tedu.hhmc.base.response.StatusCode;

import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public UserVO login(UserLoginParam userLoginParam) {
        log.debug("登录业务,参数:{}",userLoginParam);
        UserVO userVO = userMapper.selectByPhone(userLoginParam.getPhone());
        if(userVO == null){
            throw new ServiceException(StatusCode.PHONE_ERROR);
        }
        if(!userVO.getPassword().equals(userLoginParam.getPassword())){
            throw new ServiceException(StatusCode.PASSWORD_ERROR);
        }
        return userVO;
    }

    /**
     * 查询(医生)用户
     *
     * @param id (医生)用户主键
     * @return (医生)用户
     */
    @Override
    public UserVO selectUserById(Long id)
    {
        return userMapper.selectUserById(id);
    }

    /**
     * 查询(医生)用户列表
     *
     * @param user (医生)用户
     * @return (医生)用户
     */
    @Override
    public List<UserVO> selectUserList(User user)
    {
        log.debug("查询所有医生信息列表业务,参数:无");
        return userMapper.selectUserList(user);
    }

    /**
     * 新增(医生)用户
     *
     * @param user (医生)用户
     * @return 结果
     */
    @Override
    public int insertUser(User user)
    {
        return userMapper.insertUser(user);
    }

    /**
     * 修改(医生)用户
     *
     * @param user (医生)用户
     * @return 结果
     */
    @Override
    public int updateUser(User user)
    {
        return userMapper.updateUser(user);
    }

    /**
     * 批量删除(医生)用户
     *
     * @param ids 需要删除的(医生)用户主键
     * @return 结果
     */
    @Override
    public int deleteUserByIds(Long[] ids)
    {
        return userMapper.deleteUserByIds(ids);
    }

    /**
     * 删除(医生)用户信息
     *
     * @param id (医生)用户主键
     * @return 结果
     */
    @Override
    public int deleteUserById(Long id)
    {
        return userMapper.deleteUserById(id);
    }
}







